// src/pages/AdminDashboard.js
import React, { useEffect, useState } from 'react';
import { jwtDecode } from 'jwt-decode';
import Navbar from '../components/Navbar';
import axios from 'axios';
import UserTable from '../components/UserTable';
import AdminMenu from '../components/AdminMenu';
import '../assets/styles/AdminDashboard.css';

const AdminDashboard = () => {
  const [userData, setUserData] = useState(null);
  const [selectedMenu, setSelectedMenu] = useState('user-management'); // 控制菜单切换

  useEffect(() => {
    const token = localStorage.getItem('token');
    if (token) {
      const decoded = jwtDecode(token); // 假设 token 包含用户名和邮箱
      setUserData(decoded);
    }
  }, []);

  const renderContent = () => {
    switch (selectedMenu) {
      case 'user-management':
        return <UserTable />;
      case 'other-feature':
        return <div>其他功能待实现</div>;
      default:
        return <div>请选择功能</div>;
    }
  };

  return (
    <div className="admin-dashboard">
      {userData && <Navbar userData={userData} />}
      <h3>管理员界面</h3>
      <div className="dashboard-layout">
        <AdminMenu setSelectedMenu={setSelectedMenu} />
        <div className="dashboard-content">{renderContent()}</div>
      </div>
    </div>
  );
};

export default AdminDashboard;

